home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / EVISION1.ARJ / DEMO.CPP < prev    next >
C/C++ Source or Header  |  1992-05-19  |  12KB  |  303 lines

  1. //
  2. //   Name of program  : EVISION.EXE
  3. //   Version          : 1.0
  4. //   Last modified    : may 17th, 1992
  5. //   Author           : Rémy Gendron
  6. //   What it does     : EasyVision 1.0 demonstration program.
  7. //
  8. //
  9. // ---- Library Header Files -----------------------------------------------
  10.  
  11. #include <conio.h>
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14. #include <time.h>
  15. #include <ctype.h>
  16.  
  17.  
  18. // ---- Global Macros ------------------------------------------------------
  19.  
  20. #include "evmacros.hpp"
  21.  
  22.  
  23. // ---- Header files of External Functions Called --------------------------
  24.  
  25. #include "assert.hpp"
  26. #include "tdesktop.hpp"
  27. #include "tstatusline.hpp"
  28. #include "tmenubar.hpp"
  29. #include "getkey.hpp"
  30. #include "twindow.hpp"
  31.  
  32.  
  33. // ---- Local Prototypes ---------------------------------------------------
  34.  
  35. void viewfile ( tstatusline huge *slptr ) ;
  36. void demowindow ( tstatusline huge *slptr ) ;
  37. void about ( tstatusline huge *slptr ) ;
  38.  
  39.  
  40. // ---- Global Variables ---------------------------------------------------
  41.  
  42.    char huge *demohelp =                                 // General helptext
  43.  
  44.    "~TNG SOFT~ proudly presents ~EasyVision 1.0~.\n\n"
  45.    "This is the ~EasyVison~ demonstration program.  EasyVision is a "
  46.    "collection of C++ ~functions~ and ~classes~.  It will provide you with "
  47.    "the tools to easily produce professional looking programs, in a "
  48.    "fraction of the time normaly needed for such elegance and "
  49.    "performance !\n\n\n  All of this demo program was done with "
  50.    "less than 150 lines of real coding !\n\n  EasyVison was created to be "
  51.    "~powerful~, ~reliable~ and ~simple~ to use !  This is not a librairy "
  52.    "where you have to learn 3 billion new commands.  In fact, there are "
  53.    "only ~4 classes~ and ~10 functions~, for a total of roughly 50 commands. "
  54.    "You will routinely use only 15 to 20 of those because of "
  55.    "all the built in default values.\n\n  You will be able to create and "
  56.    "manage full featured ~windows~, complete with ~scrolling input fields~ "
  57.    "and ~push buttons~.  A ~desktop~, a ~statusline~ and a ~menubar~ "
  58.    "will get together to create a fully integrated user interface.\n\n"
  59.    "The ~F1~ key will always display an ~help "
  60.    "window~, and will be available ~everywhere in your program~, without "
  61.    "you having to write a single line of code !  "
  62.    "You don't have to format the help text either. "
  63.    "The built in help function will format the text in the help window "
  64.    "with ~word wrapping~ !\n\n"
  65.    "So, if you would like to take advantage of this library, just read "
  66.    "the manual included in the archive ~EVISION1.ZIP~, and within the "
  67.    "hour you will be on your way to a new standard in ~quality~ and "
  68.    "~ease of use~ with the EasyVison library !\n\n"
  69.    "~STARFLEET COMMAND BBS~ is the home of all of ~TNG SOFT~'s software.  "
  70.    "Give us a call !\n\n(418) 525-6899/4740/6803\n1200/2400 8N1\n"
  71.    "Fidonet address: 1:240/1701\n\n"
  72.    "Rémy Gendron" ;
  73.  
  74.  
  75. // ---- Main Function ------------------------------------------------------
  76.  
  77. void main()
  78. {
  79.    tdesktop    huge *desktop ;                             // Ptr to classes
  80.    tstatusline huge *statusline ;         // You should always use HUGE ptrs
  81.    tmenubar    huge *menubar ;
  82.    int              command ;                                // User command
  83.  
  84.  
  85.    desktop = new tdesktop ;                              // Create a desktop
  86.    assert (desktop != NULL,"main",1) ;
  87.    statusline = new tstatusline ;                       // Create statusline
  88.    assert (statusline != NULL,"main",1) ;
  89.    menubar = new tmenubar ;                                // Create menubar
  90.    assert (menubar != NULL,"main",1) ;
  91.  
  92.    desktop->insert (statusline) ;            // Insert objects in desktop to
  93.    desktop->insert (menubar) ;                 // allow the refresh function
  94.    desktop->open () ;                                     // Display desktop
  95.  
  96.    statusline->displayleft ("~F1~ Help") ;             // Display statusline
  97.  
  98.    menubar->sethelp (demohelp) ;                             // Create menus
  99.    menubar->setslptr (statusline) ;         // Match menubar with statusline
  100.    menubar->addmenu ("≡",'S',"System menu") ;
  101.    menubar->additem ("Redraw desktop  Alt-R",'R',275,
  102.                      "Redraw the screen") ;
  103.    menubar->additem () ;
  104.    menubar->additem ("About...        Alt-A",'A',286,
  105.                      "Show version and copyright informations") ;
  106.    menubar->addmenu ("Demo",'D',"EasyVision demonstrations") ;
  107.    menubar->additem ("View file...  Alt-V",'V',303,"View a text file") ;
  108.    menubar->additem ("Open window   Alt-O",'O',280,"Show an EasyVision window") ;
  109.    menubar->additem () ;
  110.    menubar->additem ("Exit demo     Alt-X",'E',301,"Exit EasyVision demo") ;
  111.    menubar->addmenu ("Examples",'E',"Just an example menu") ;
  112.    menubar->additem ("Dummy off item...  ",'Z',286,
  113.                      "Menu items can be 'offline'") ;
  114.    menubar->additem ("Do nothing item... ",'Y',277,
  115.                      "This is just an example") ;
  116.    menubar->itemsetavail ('E','Z',0) ;
  117.  
  118.    command = 0 ;
  119.    while (command != 301)                                   // Alt-X to stop
  120.    {
  121.       statusline->displayright ("Welcome to ~EasyVison~ !") ;
  122.       command = getkey (0,demohelp) ;
  123.       command = menubar->trough (command) ;
  124.  
  125.       if (command == 286) about (statusline) ;
  126.       if (command == 303) viewfile (statusline) ;
  127.       if (command == 280) demowindow (statusline) ;
  128.       if (command == 275) desktop->refresh () ;
  129.    }
  130.  
  131.                                                                 // Demo over
  132.    desktop->close () ;                                     // Restore screen
  133.  
  134.    delete statusline ;                                     // Delete classes
  135.    delete menubar ;
  136.    delete desktop ;
  137.  
  138.    return ;
  139. }                                                                // End main
  140.  
  141.  
  142. // ---- Function Definitions -----------------------------------------------
  143.  
  144. void viewfile                                  // View an external text file
  145.  
  146. ( tstatusline huge *slptr )                         // Ptr to the statusline
  147.  
  148. {
  149.    twindow  huge *winptr ;                         // Ptr to a twindow class
  150.    char     temp[41] ;                                       // To get input
  151.    int      inchar ;                                    // Input from window
  152.  
  153.  
  154.    winptr = new twindow ;                                 // Create a window
  155.    assert (winptr != NULL,"viewfile",1) ;
  156.  
  157.    winptr->winsetpos (8,20) ;                              // Display window
  158.    winptr->winsetsize (9,40) ;
  159.    winptr->winsetcolors (MAGENTA) ;
  160.    winptr->winsettitle ("View File") ;
  161.    winptr->winsethelp (demohelp) ;
  162.    winptr->winsetslptr (slptr) ;
  163.    winptr->winopen () ;
  164.    winptr->winswrite ("Enter path of file to view:",2,1,2) ;
  165.  
  166.    winptr->fieldsetlengths (40,20) ;             // Get path of file to view
  167.    winptr->fieldsetcolors (BLUE) ;
  168.    winptr->fieldsetftr (3,":\\.") ;
  169.    winptr->fieldcreate (4,10,"","Enter complete path of some text file") ;
  170.    winptr->buttoncreate (6,2,"   Ok",13,"Accept path") ;
  171.    winptr->buttoncreate (6,12,"  Esc",27,"Abort file viewing") ;
  172.    inchar = winptr->wininput () ;
  173.    winptr->fieldgetasw (temp) ;
  174.    winptr->winclose () ;
  175.  
  176.    if (inchar == 13)                                       // If accept path
  177.    {
  178.       winptr->winsetpos (2,1) ;                         // Open a big window
  179.       winptr->winsetsize (999,999) ;
  180.       winptr->winsetcolors (BLUE) ;
  181.       winptr->winsettitle ("View file") ;
  182.       winptr->winsethelp (demohelp) ;
  183.       winptr->winsetslptr (slptr) ;
  184.       winptr->winopen () ;
  185.       slptr->displayright ("Viewing file...") ;
  186.       winptr->wintextfile (temp) ;
  187.       winptr->winclose () ;
  188.    }
  189.  
  190.    slptr->displayright () ;
  191.    delete (winptr) ;
  192.  
  193.    return ;
  194. }                                                           // End view file
  195.  
  196.  
  197. // ---- Function Definitions -----------------------------------------------
  198.  
  199. void demowindow                                        // Play with a window
  200.  
  201. ( tstatusline huge *slptr )                         // Ptr to the statusline
  202.  
  203. {
  204.    twindow  huge *winptr ;                         // Ptr to a twindow class
  205.    int      inchar ;                                           // User input
  206.  
  207.  
  208.    randomize () ;                            // Init random number generator
  209.  
  210.    winptr = new twindow ;                                 // Create a window
  211.    assert (winptr != NULL,"demowindow",1) ;
  212.  
  213.    winptr->winsetpos (7,20) ;                              // Display window
  214.    winptr->winsetsize (13,40) ;
  215.    winptr->winsetcolors (BLUE) ;
  216.    winptr->winsettitle ("Demo Window") ;
  217.    winptr->winsethelp (demohelp) ;
  218.    winptr->winsetslptr (slptr) ;
  219.    winptr->winopen () ;
  220.    winptr->winwrite ("Alpha",2,2) ;
  221.    winptr->winwrite ("Numeric",2,20) ;
  222.    winptr->winwrite ("AlphaNumeric",4,2) ;
  223.    winptr->winwrite ("No restrictions",4,20) ;
  224.  
  225.    winptr->fieldsetlengths (30,15) ;             // Create some input fields
  226.    winptr->fieldsetcolors (GREEN) ;
  227.    winptr->fieldsetftr (1," ") ;
  228.    winptr->fieldcreate (3,2,"Hello there","This field only accepts letters") ;
  229.    winptr->fieldsetftr (2,"") ;
  230.    winptr->fieldcreate (3,20,"1992","This field only accepts digits") ;
  231.    winptr->fieldsetftr (3," ") ;
  232.    winptr->fieldcreate (5,2,"Enterprise NCC 1701 D",
  233.                             "This field accepts letters and digits") ;
  234.    winptr->fieldsetftr (0) ;
  235.    winptr->fieldcreate (5,20,"EasyVision 1.0 by TNG SOFT !",
  236.                              "This field accepts anything") ;
  237.  
  238.                                                       // Create some buttons
  239.  
  240.    winptr->buttoncreate (7,2,"  Move",'M',"Randomly move window") ;
  241.    winptr->buttoncreate (7,29,"  Esc",27,"Close window") ;
  242.    winptr->buttoncreate (10,2,"   Up",'U',"Move window up") ;
  243.    winptr->buttoncreate (10,11,"  Down",'D',"Move window down") ;
  244.    winptr->buttoncreate (10,20,"  Left",'L',"Move window Left") ;
  245.    winptr->buttoncreate (10,29," Right",'R',"Move window Right") ;
  246.  
  247.    inchar = 0 ;
  248.    while (inchar != 27)                                 // Make window alive
  249.    {
  250.       inchar = winptr->wininput () ;
  251.       if (inchar <= 255) inchar = toupper (inchar) ;
  252.  
  253.       if (inchar == 'U') winptr->winscroll ('U') ;
  254.       if (inchar == 'D') winptr->winscroll ('D') ;
  255.       if (inchar == 'L') winptr->winscroll ('L') ;
  256.       if (inchar == 'R') winptr->winscroll ('R') ;
  257.       if (inchar == 'M') winptr->winmove (2+random(11),1+random(41)) ;
  258.    }
  259.  
  260.    winptr->winclose () ;
  261.    delete (winptr) ;
  262.  
  263.    return ;
  264. }                                                          // End demowindow
  265.  
  266. // ---- Function Definitions -----------------------------------------------
  267.  
  268. void about                                     // Display info on EasyVision
  269.  
  270. ( tstatusline huge *slptr )                         // Ptr to the statusline
  271.  
  272. {
  273.    twindow  huge *winptr ;                         // Ptr to a twindow class
  274.  
  275.    winptr = new twindow ;                                 // Create a window
  276.    assert (winptr != NULL,"about",1) ;
  277.  
  278.    winptr->winsetpos (5,20) ;                              // Display window
  279.    winptr->winsetsize (15,40) ;
  280.    winptr->winsetcolors (BLUE) ;
  281.    winptr->winsettitle ("About") ;
  282.    winptr->winsethelp (demohelp) ;
  283.    winptr->winsetslptr (slptr) ;
  284.    winptr->winopen () ;
  285.    winptr->winwrite ("EasyVision 1.0",2,1,2) ;
  286.    winptr->winwrite ("The easy to use and powerful",4,1,2) ;
  287.    winptr->winwrite ("text mode interface !",5,1,2) ;
  288.    winptr->winwrite ("Copyright (c) 1992 by",7,1,2) ;
  289.    winptr->winwrite ("TNG SOFT",9,1,2) ;
  290.    winptr->winwrite ("The Next Generation Software",10,1,2) ;
  291.  
  292.    winptr->buttoncreate (12,16," Enter",13,"Press ~ENTER~ to continue") ;
  293.    (void) winptr->buttoninput () ;
  294.  
  295.    winptr->winclose () ;
  296.    delete (winptr) ;
  297.  
  298.    return ;
  299. }                                                               // End about
  300.  
  301.  
  302. // ---- End Main Source File -----------------------------------------------
  303.